package com.ruoyi.report.controller;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.LeaveMessage;
import com.ruoyi.report.service.ILeaveMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


/**
 * 留言板信息Controller
 * 
 * @author huanshihao
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/project/message")
public class LeaveMessageController extends BaseController
{
    private String prefix = "project/message";

    @Autowired
    private ILeaveMessageService leaveMessageService;

    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询留言板信息列表
     */
    @GetMapping("/list")

    public TableDataInfo list(LeaveMessage leaveMessage)
    {
        startPage();
        List<LeaveMessage> list = leaveMessageService.selectLeaveMessageList(leaveMessage);
        return getDataTable(list);
    }

    /**
     * 导出留言板信息列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LeaveMessage leaveMessage)
    {
        List<LeaveMessage> list = leaveMessageService.selectLeaveMessageList(leaveMessage);
        ExcelUtil<LeaveMessage> util = new ExcelUtil<LeaveMessage>(LeaveMessage.class);
        return util.exportExcel(list, "message");
    }

    /**
     * 新增留言板信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言板信息
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody  LeaveMessage leaveMessage)
    {
        return toAjax(leaveMessageService.insertLeaveMessage(leaveMessage));
    }

    /**
     * 修改留言板信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LeaveMessage leaveMessage = leaveMessageService.selectLeaveMessageById(id);
        mmap.put("leaveMessage", leaveMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言板信息
     */
    @PostMapping("/edit")
    public AjaxResult editSave(LeaveMessage leaveMessage)
    {
        return toAjax(leaveMessageService.updateLeaveMessage(leaveMessage));
    }

    /**
     * 删除留言板信息
     */
    @PostMapping( "/remove")
    public AjaxResult remove(String ids)
    {
        return toAjax(leaveMessageService.deleteLeaveMessageByIds(ids));
    }
}
